<rd-header>
  <rd-header-title title="Container list">
    <a data-toggle="tooltip" title="Refresh" ui-sref="containers" ui-sref-opts="{reload: true}">
      <i class="fa fa-refresh" aria-hidden="true"></i>
    </a>
    <i id="loadContainersSpinner" class="fa fa-cog fa-spin" style="margin-left: 5px;"></i>
  </rd-header-title>
  <rd-header-content>Containers</rd-header-content>
</rd-header>

<div class="col-lg-12">
  <rd-widget>
    <rd-widget-header icon="fa-server" title="Containers">
      <div class="pull-right">
        Items per page:
        <select ng-model="state.pagination_count" ng-change="changePaginationCount()">
          <option value="0">All</option>
          <option value="10">10</option>
          <option value="25">25</option>
          <option value="50">50</option>
          <option value="100">100</option>
        </select>
      </div>
    </rd-widget-header>
    <rd-widget-taskbar classes="col-lg-12">
      <div class="pull-left">
        <div class="btn-group" role="group" aria-label="...">
          <button type="button" class="btn btn-success btn-responsive" ng-click="startAction()" ng-disabled="!state.selectedItemCount || state.noStoppedItemsSelected"><i class="fa fa-play space-right" aria-hidden="true"></i>Start</button>
          <button type="button" class="btn btn-danger btn-responsive" ng-click="stopAction()" ng-disabled="!state.selectedItemCount || state.noRunningItemsSelected"><i class="fa fa-stop space-right" aria-hidden="true"></i>Stop</button>
          <button type="button" class="btn btn-danger btn-responsive" ng-click="killAction()" ng-disabled="!state.selectedItemCount"><i class="fa fa-bomb space-right" aria-hidden="true"></i>Kill</button>
          <button type="button" class="btn btn-primary btn-responsive" ng-click="restartAction()" ng-disabled="!state.selectedItemCount"><i class="fa fa-refresh space-right" aria-hidden="true"></i>Restart</button>
          <button type="button" class="btn btn-primary btn-responsive" ng-click="pauseAction()" ng-disabled="!state.selectedItemCount || state.noRunningItemsSelected"><i class="fa fa-pause space-right" aria-hidden="true"></i>Pause</button>
          <button type="button" class="btn btn-primary btn-responsive" ng-click="unpauseAction()" ng-disabled="!state.selectedItemCount || state.noPausedItemsSelected"><i class="fa fa-play space-right" aria-hidden="true"></i>Resume</button>
          <button type="button" class="btn btn-danger btn-responsive" ng-click="confirmRemoveAction()" ng-disabled="!state.selectedItemCount"><i class="fa fa-trash space-right" aria-hidden="true"></i>Remove</button>
        </div>
        <a class="btn btn-primary" type="button" ui-sref="actions.create.container"><i class="fa fa-plus space-right" aria-hidden="true"></i>Add container</a>
      </div>
      <div class="pull-right">
        <input type="checkbox" ng-model="state.displayAll" id="displayAll" ng-change="toggleGetAll()" style="margin-top: -2px; margin-right: 5px;"/><label for="displayAll">Show all containers</label>
        <input type="text" id="filter" ng-model="state.filter" placeholder="Filter..." class="form-control input-sm" />
      </div>
    </rd-widget-taskbar>
    <rd-widget-body classes="no-padding">
      <div class="table-responsive">
        <table class="table table-hover">
          <thead>
            <tr>
              <th>
                <input type="checkbox" ng-model="allSelected" ng-change="selectItems(allSelected)" />
              </th>
              <th>
                <a ui-sref="containers" ng-click="order('Status')">
                  State
                  <span ng-show="sortType == 'Status' && !sortReverse" class="glyphicon glyphicon-chevron-down"></span>
                  <span ng-show="sortType == 'Status' && sortReverse" class="glyphicon glyphicon-chevron-up"></span>
                </a>
              </th>
              <th>
                <a ui-sref="containers" ng-click="order('Names')">
                  Name
                  <span ng-show="sortType == 'Names' && !sortReverse" class="glyphicon glyphicon-chevron-down"></span>
                  <span ng-show="sortType == 'Names' && sortReverse" class="glyphicon glyphicon-chevron-up"></span>
                </a>
              </th>
              <th>
                <a ui-sref="containers" ng-click="order('Image')">
                  Image
                  <span ng-show="sortType == 'Image' && !sortReverse" class="glyphicon glyphicon-chevron-down"></span>
                  <span ng-show="sortType == 'Image' && sortReverse" class="glyphicon glyphicon-chevron-up"></span>
                </a>
              </th>
              <th ng-if="state.displayIP">
                <a ui-sref="containers" ng-click="order('IP')">
                  IP Address
                  <span ng-show="sortType == 'IP' && !sortReverse" class="glyphicon glyphicon-chevron-down"></span>
                  <span ng-show="sortType == 'IP' && sortReverse" class="glyphicon glyphicon-chevron-up"></span>
                </a>
              </th>
              <th ng-if="applicationState.endpoint.mode.provider === 'DOCKER_SWARM'">
                <a ui-sref="containers" ng-click="order('Host')">
                  Host IP
                  <span ng-show="sortType == 'Host' && !sortReverse" class="glyphicon glyphicon-chevron-down"></span>
                  <span ng-show="sortType == 'Host' && sortReverse" class="glyphicon glyphicon-chevron-up"></span>
                </a>
              </th>
              <th>
                <a ui-sref="containers" ng-click="order('Ports')">
                  Published Ports
                  <span ng-show="sortType == 'Ports' && !sortReverse" class="glyphicon glyphicon-chevron-down"></span>
                  <span ng-show="sortType == 'Ports' && sortReverse" class="glyphicon glyphicon-chevron-up"></span>
                </a>
              </th>
              <th ng-if="applicationState.application.authentication">
                <a ui-sref="containers" ng-click="order('ResourceControl.Ownership')">
                  Ownership
                  <span ng-show="sortType == 'ResourceControl.Ownership' && !sortReverse" class="glyphicon glyphicon-chevron-down"></span>
                  <span ng-show="sortType == 'ResourceControl.Ownership' && sortReverse" class="glyphicon glyphicon-chevron-up"></span>
                </a>
              </th>
            </tr>
          </thead>
          <tbody>
            <tr dir-paginate="container in (state.filteredContainers = ( containers | filter:state.filter | orderBy:sortType:sortReverse | itemsPerPage: state.pagination_count))">
              <td><input type="checkbox" ng-model="container.Checked" ng-change="selectItem(container)"/></td>
              <td>
                <span ng-if="['starting','healthy','unhealthy'].indexOf(container.Status) !== -1" class="label label-{{ container.Status|containerstatusbadge }} interactive" uib-tooltip="This container has a health check">{{ container.Status }}</span>
                <span ng-if="['starting','healthy','unhealthy'].indexOf(container.Status) === -1" class="label label-{{ container.Status|containerstatusbadge }}">{{ container.Status }}</span>
              </td>
              <td ng-if="applicationState.endpoint.mode.provider === 'DOCKER_SWARM'"><a ui-sref="container({id: container.Id})">{{ container|swarmcontainername|truncate: 40}}</a></td>
              <td ng-if="applicationState.endpoint.mode.provider !== 'DOCKER_SWARM'"><a ui-sref="container({id: container.Id})">{{ container|containername|truncate: 40}}</a></td>
              <td><a ui-sref="image({id: container.Image})">{{ container.Image | hideshasum }}</a></td>
              <td ng-if="state.displayIP">{{ container.IP ? container.IP : '-' }}</td>
              <td ng-if="applicationState.endpoint.mode.provider === 'DOCKER_SWARM'">{{ container.hostIP }}</td>
              <td>
                <a ng-if="container.Ports.length > 0" ng-repeat="p in container.Ports" class="image-tag" ng-href="http://{{ PublicURL || p.host }}:{{p.public}}" target="_blank">
                  <i class="fa fa-external-link" aria-hidden="true"></i> {{p.public}}:{{ p.private }}
                </a>
                <span ng-if="container.Ports.length == 0" >-</span>
              </td>
              <td ng-if="applicationState.application.authentication">
                <span>
                  <i ng-class="container.ResourceControl.Ownership | ownershipicon" aria-hidden="true"></i>
                  {{ container.ResourceControl.Ownership ? container.ResourceControl.Ownership : container.ResourceControl.Ownership = 'public' }}
                </span>
              </td>
            </tr>
            <tr ng-if="!containers">
              <td colspan="9" class="text-center text-muted">Loading...</td>
            </tr>
            <tr ng-if="containers.length == 0">
              <td colspan="9" class="text-center text-muted">No containers available.</td>
            </tr>
          </tbody>
        </table>
        <div ng-if="containers" class="pull-left pagination-controls">
          <dir-pagination-controls></dir-pagination-controls>
        </div>
      </div>
    </rd-widget-body>
  </rd-widget>
</div>
